<?php
require $this->website['path']['action'] . '/admin/islogin.php';

$json = array('status' => 'error', 'msg' => 'error', 'data' => '');

$id = fn_post('id');

if (!is_numeric($id)) {
	$json['msg'] = '删除失败,链接编号错误';
} elseif (!$this->website['class']['db']->table('link')->where('id=?', $id)->limit(1)->count()) {
	$json['msg'] = '删除失败,未找到编号为:' . $id . '的链接，或已被是删除';
} else {
	$link = $this->website['class']['db']
		->table('link')
		->field('image')
		->where('id=?', $id)
		->one();
	$num = $this->website['class']['db']
		->table('link')
		->where('id=?', $id)
		->limit(1)
		->delete();
	if ($num) {
		$json['status'] = 'ok';
		$json['msg'] = '链接删除成功';

		$path = $this->website['path']['root'] . $link['image'];
		if (is_file($path)) {
			unlink($path);
		}
		$json['data'] = $image;
	} else {
		$json['msg'] = '链接删除失败';
		// $json['data'] = $this->website['class']['db']->sql;
	}
}

echo json_encode($json);